import basic from './basic.js';
var actmodel = new basic();
 
//订单列表
actmodel.offset = function (that, reset, para, xcsorts) { 
  if(!xcsorts)
  {
    xcsorts=[["id", "desc"], ["modifytime", "desc"]] ;
  }
 
  var acturlpara = {};   
  acturlpara["url"] = "entry/wxapp/cardpro_contents"
  if (para) {
    para["op"] = "offset"
    para['plugin']="smapi"
  }
  else {
    this.wherepara["plugin"] = "smapi"
    this.wherepara["op"] = "offset"
  }
  return actmodel.pagelist(acturlpara, that, reset, para, xcsorts);
}


//获取卡券信息
actmodel.getmodel = function (id) {
  var app = getApp();
  return new Promise((resolve, reject) => {
    app.util.request({
      'url': 'entry/wxapp/cardpro_contents',
      showLoading: true,      
      'data': { "op": "getmodel",plugin:'smapi' ,id},
      'method': "post",
      success: function (res) {
      
        resolve(res.data.data);
     
      },
      fail: function (res) {
        resolve({ status: -1, "message": "操作失败2" });
      },
      complete: function () {
      }
    },true);
  })
} 
//下单
actmodel.createorder = function (model) {
  var app = getApp();
  var data = { "op": "createorder",plugin:'smapi', model: model }
  return new Promise((resolve, reject) => {
    app.util.request({
      'url': 'entry/wxapp/cardpro_contents',
      'data': data,
      'method': "get",
      success: function (res) {
        if (res.data.errno == 0) {

          resolve(res.data.data);

        }
        reject(res.data.message);
      },
      fail: function (res) {

        reject(((res.data && res.data.message) ? res.data.message : res.errMsg));
      },
      complete: function () {
      }
    });
  });
}
actmodel.queryorder=function (id) {

  var app = getApp();
  var data = { "op": "queryorder", id: id,plugin:'smapi'}
  return new Promise((resolve, reject) => {
    app.util.request({
      'url': 'entry/wxapp/api_huka',
      'data': data,
      'method': "post",
      success: function (res) {
        
        resolve(res.data.data);
      }
    })
})
}

actmodel.sendnotice=function (ordernum) {

  var app = getApp();
  var data = { "op": "sendnotice", ordernum: ordernum,plugin:'smapi'}
  return new Promise((resolve, reject) => {
    app.util.request({
      'url': 'entry/wxapp/api_huka',
      'data': data,
      'method': "post",
      success: function (res) {
        
        resolve(res.data.data);
      }
    })
})
}
module.exports = actmodel;
